package com.jdls.tanhua.web;

import com.jdls.tanhua.server.CommentServer;
import com.jdls.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 嘉德罗斯
 * @date 2021/10/29
 */
@RequestMapping("/comments")
@RestController
public class CommentWeb {

    @Autowired
    private CommentServer commentServer;

    @PostMapping
    //发布评论
    public ResponseEntity saveComment(@RequestBody Map map){
        commentServer.saveComment(map);
        return ResponseEntity.ok(null);
    }

    @GetMapping
    //查看动态的评论
    public ResponseEntity findComment(String movementId,
                                      @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = commentServer.findComment(movementId,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable String id){
        Integer like = commentServer.like(id);
        return ResponseEntity.ok(like);
    }

    @GetMapping("/{id}/dislike")
    //取消点赞
    public ResponseEntity dislike(@PathVariable String id){
        Integer like = commentServer.dislike(id);
        return ResponseEntity.ok(like);
    }
}
